<template>
  <div class="server-main">
    <el-form :inline="true" v-model="modelData" class="search-form">
      <el-form-item label="需求内容" class="form-input">
        <el-input v-model.trim="modelData.requireContent" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button id="btn" size="small" type="primary" @click="onSubmit(1)"
          >查询</el-button
        >
      </el-form-item>
    </el-form>

    <div class="server-table">
      <div class="table-title">
        <span class="table-title-text">智能推荐记录</span>
        <div>
          <el-button type="primary" size="small" @click="openCreateProperty"
            >智能推荐</el-button
          >
        </div>
      </div>
      <el-table :data="tableList" class="km-table">
        <el-table-column
          type="index"
          label="ID"
          width="50"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="requireContent"
          label="需求内容"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="recommendCaseCount"
          label="推荐用例数量"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="recommendCaseMode"
          label="应用用例模型"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="recommendToolCount"
          label="推荐工具数量"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="recommendToolMode"
          label="应用工具模型"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="操作时间"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="createUseId"
          label="操作人员"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>

        <el-table-column label="操作" align="center" width="200">
          <template slot-scope="scope">
            <el-link
              :underline="false"
              type="primary"
              class="ontology-edit"
              @click.native.prevent="openEditOntology(scope.row.recommendId)"
              >查看</el-link
            >
            <el-link
              :underline="false"
              type="primary"
              class="ontology-edit"
              @click.native.prevent="deleteProperty(scope.row.recommendId)"
              >删除</el-link
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        class="km-pagination"
        background
        :small="true"
        layout="total, prev, pager, next,sizes, jumper"
        :total="total"
        :hide-on-single-page="!total"
        :page-size.sync="modelData.pageSize"
        :pager-count="7"
        :page-sizes="[10, 20, 30]"
        :current-page="modelData.pageNum"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
import { updateCookie } from "@/plugins/utils/auth";
import { mapState, mapMutations } from "vuex";
export default {
  name: "intelligenceRec",
  components: {},
  data: () => {
    return {
      modelData: {
        requireContent: "", // 需求内容
        pageNum: 1, // 页码
        pageSize: 10, // 每页条数
      },
      tableList: [], // 本体类别列表
      total: 0, // 数据总条数
    };
  },
  computed: {
    ...mapState({
      containerDom: (state) => state.server.containerDom,
    }),
  },
  async created() {
    if (this.$route.query.token) {
      updateCookie("token", this.$route.query.token);
    }
    this.getTableList();
  },
  methods: {
    // 查询
    onSubmit(pageNum) {
      this.modelData.pageNum = pageNum ? pageNum : this.modelData.pageNum;
      this.getTableList();
    },

    // 获取本体模型属性列表
    async getTableList() {
      const { pageNum, pageSize, requireContent } = this.modelData;
      let params = {
        requireContent,
        pageNum,
        pageSize,
      };
      let res = await this.$axios.post(
        this.$api.caseResultRec.zehaoObj.getTableList,
        params
      );
      if (res.data.message === "操作成功") {
        this.total = res.data.data.total;
        this.tableList = res.data.data.list;
        return;
      } else {
        this.$message.warning(res.data.message);
      }
    },

    // 修改当前页码
    handleCurrentChange(page) {
      this.modelData.pageNum = page;
      this.getTableList();
    },
    // 修改每页显示数量
    handleSizeChange() {
      this.getTableList();
    },

    // 删除当前属性
    deleteProperty(recommendId) {
      this.$confirm("是否删除该数据？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          let params = {
            recommendId,
          };
          let res = await this.$axios.post(
            this.$api.caseResultRec.zehaoObj.deleteByRecommendId,
            params
          );
          if (res.data.code !== 200) {
            this.$message.warning(res.data.message);
            return;
          }
          this.$message.success("删除成功!");
          this.getTableList();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    // 查看
    openEditOntology(recommendId) {
      this.$router.push({
        path: "/caseResultRec/intelligenceRecDetail",
        query: {
          recommendId,
        },
      });
    },

    // 智能推荐
    openCreateProperty() {
      this.$router.push(`/caseResultRec/intelligenceRecDetail`);
    },
  },
};
</script>
<style lang="scss" scoped>
.server-main {
  position: relative;

  .search-form {
    background: #ffffff;
    border-radius: 4px;
    padding: 16px 32px;
    .el-form-item {
      margin-bottom: 0;
    }

    .form-input {
      margin-right: 32px;
      .el-input,
      .el-select {
        ::v-deep .el-input__inner {
          width: 240px;
          height: 32px;
          background: #ffffff;
          border-radius: 2px;
          border: 1px solid #e0e0e0;
        }
      }
    }
  }
  .server-table {
    margin-top: 16px;
    padding: 16px 32px 64px;
    background: #ffffff;
    border-radius: 4px;

    .table-title {
      display: flex;
      justify-content: space-between;
      align-items: center;

      .table-title-text {
        margin: 8px 0;
        font-size: 16px;
        line-height: 16px;
        border-left: 5px solid $--color-primary;
        padding-left: 10px;
      }

      margin-bottom: 10px;
    }
  }

  .ontology-edit {
    padding: 0 10px;
    & + .ontology-edit {
      border-left: 1px solid #dddddd;
    }
  }

  ::v-deep .el-table__append-wrapper {
    padding: 10px;
  }

  ::v-deep .el-dialog {
    width: 500px;
    border-radius: 5px;
  }

  .dialog-inline {
    ::v-deep .el-form-item__content {
      width: 300px;
    }

    button.el-button {
      background-color: $--color-primary !important;
      color: #fff !important;
      line-height: 1.2;
    }
  }
}
</style>
